package com.example.educational.config;

import com.example.educational.controller.utils.ProjectInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 添加拦截器请求配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*添加拦截器*/
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(MyInterceptor());
        /*拦截所有请求*/
        interceptorRegistration
                .addPathPatterns("/innAppService/**")  // addPathPatterns 用于添加拦截规则
                .excludePathPatterns("/innAppService/dingUsers")
                .excludePathPatterns("/innAppService/searchReadPeople")
                .excludePathPatterns("/innAppService/searchUnReadPeople")
                .excludePathPatterns("/innAppService/callback");
    }

    @Bean
    public ProjectInterceptor MyInterceptor() {
        return new ProjectInterceptor();
    }

}
